<template>
  <div class="logs-data">
    <el-card :body-style="{ padding: '0px' }">
      <div slot="header">
        <tools-btn
          :toolsData="toolsData"
          @addData="addData"
          @refresh="refresh"
          @search="search"
          @fieldSet="fieldSet"
          @hasOperation="hasOperation"
        />
      </div>
      <table-list
        id="tableExcel"
        :table="table"
        ref="tableList"
        @handleEdit="handleEdit"
        @handleDel="handleDel"
      >
        <template slot-scope="props" slot="checkResult">
          <div>
            <span v-text="props.obj.row.checkResult === '1'?'审核未通过':'审核通过'"></span>
          </div>
        </template>
        <template slot-scope="props" slot="imageUrl">
          <a
            v-text="props.obj.row.imageUrl=== '' ?'':'详情'"
            style="color:#67C23A;"
            @click="dianji(props.obj.row.imageUrl)"
          />
        </template>
      </table-list>
      <pagination
        :page="page"
        @pageSizeChange="pageSizeChange"
        @pageCurrentChange="pageCurrentChange"
      />
    </el-card>

    <el-dialog
      :title="editDialog.title"
      v-if="editDialog.visible"
      :visible.sync="editDialog.visible"
      @close="closeDialog('editDialog')"
      width="30%"
    >
      <el-form :model="editDialog.data" ref="editDialog.data" label-width="90px">
        <el-form-item label="审核结果">
          <!-- <el-input v-model="editDialog.data.checkResult" size="mini" /> -->
          <el-select v-model="editDialog.data.checkResult" size="mini" placeholder="请选择审核结果">
            <el-option label="审核通过" value="0"></el-option>
            <el-option label="审核未通过" value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button size="small" plain @click="closeDialog('editDialog')">取 消</el-button>
        <el-button slot="reference" type="primary" @click="VerifyRecord" size="small" v-text="'提 交'" plain />
      </span>
    </el-dialog>
    <!-- 图片 -->
    <el-dialog
      v-if="dialogTableVisible.visible"
      :visible.sync="dialogTableVisible.visible"
      width="30%"
    >
      <div v-for="url in urls" :key="url">
        <img :src="url" style="width:100%;border: 2px solid #DCDFE6;" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ToolsBtn from "../../components/Tools/ToolsBtn";
import TableList from "../../components/Table/TableList";
import TableProp from "../../utils/tableProps.js";
import Pagination from "../../components/Pagination/pagination";
import PageProp from "../../utils/pageProps3.js";
import THead from "./HLogs.js";
export default {
  name: "Logs",
  data() {
    return {
      GetToken:JSON.parse(sessionStorage.getItem("token")),
      table: TableProp,
      page: PageProp,
      toolsData: {
        title: "维护记录查询",
        oBtnShow: [
          { btn0: false }, // 新增按钮
          { btn1: true }, // 刷新按钮
          { btn2: false }, // 搜索按钮
          { btn3: false }, // 设置按钮
          { btn4: true } // 导出Excel按钮
        ]
      },
      editDialog: {
        title: "编 辑",
        visible: false,
        submitVisible: false,
        data: null
      },
      imgDialog: {
        visible: false,
        submitVisible: false
      },
      dialogTableVisible: {
        visible: false,
        data: null
      },
      showPrise: false,
      showRentPrise: false,
      imgUrl: "",
      timeData: "",
      urls: [],
      EditForm:{
        checkResult:''
      }
    };
  },
  components: {
    ToolsBtn,
    TableList,
    Pagination
  },
  created() {
    this.table.tHead = THead;
    this.table.hasOperation = true;
    this.table.operation.data = [
      {
        id: 1,
        label: "审 核",
        Fun: "handleEdit",
        btnType: "text",
        plain: false,
        size: "mini",
        className: "handleEdit"
      }
    ];
    this.table.identifier = true;
    this.getList(1, 10);
  },
  methods: {
    // 审核确定
    VerifyRecord(){
      this.$confirm('你将要修改此记录的审批结果, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params = {
            checkPersonName:this.GetToken.personName,
            checkResult: this.editDialog.data.checkResult,
            id: this.editDialog.data.id
          }
          this.$api.RECORD.upData(params)
          .then(res => {
            this.editDialog.visible = false;
            this.getList(1, 10);            
          })
          .catch(() => {
            // console.log(err);
            this.editDialog.visible = false;
          });
        }).catch(() => {
          this.editDialog.visible = false;
          this.$message({
            type: 'info',
            message: '已取消操作'
          });          
        });
    },
    // 新增数据
    addData() {
      // console.log("新增数据")
      this.handleEdit();
    },
    dianji(name) {
      this.dialogTableVisible.visible = true;
      this.imgDialog.submitVisible = true;
      var three = name.split(",");
      this.urls = three;
    },
    // 增加数据
    handleAdd() {
      // const params = {
      //   id: this.editDialog.data.id,
      //   ID_IMEI: this.editDialog.data.id_IMEI,
      //   deviceName: this.editDialog.data.deviceName,
      //   location: this.editDialog.data.location,
      //   rname: this.editDialog.data.rname,
      //   rid: this.editDialog.data.rid
      // }
      // console.log(params)
    },
    // 刷新数据
    refresh() {
      // console.log("刷新数据")
      this.getList(1, 10);
    },
    // 搜索数据
    search() {
      // console.log("搜索数据")
    },
    // 设置字段
    fieldSet() {
      // console.log("设置字段")
    },
    // 隐藏表格操作列
    hasOperation(res) {
      // console.log("隐藏表格操作列");
      // this.table.hasOperation = !this.table.hasOperation;
      this.table.hasOperation = res;
    },
    getList(pageNo, pageSize) {
      this.table.data = [];
      this.table.loading = true;
      const params = {
        pageNo,
        pageSize
      };
      // console.log(params)
      this.$api.RECORD.getData(params)
        .then(res => {
          const data = res.data;
          const total = res.count;
          this.table.data = data;
          this.page.total = total;
          this.table.loading = false;
        })
        .catch(() => {
          // console.log(err);
        });
    },
    // 分页大小
    pageSizeChange(size) {
      // console.log(`每页 ${size} 条`);
      const tableDataLength = this.table.data.length;
      this.page.pageSize = size;
      if (tableDataLength < this.page.pageSize) {
        this.getList(1, size);
      } else {
        const pageNo = this.page.currentPage;
        this.getList(pageNo, size);
      }
    },
    // 翻页
    pageCurrentChange(pageNo) {
      // console.log(`当前页: ${pageNo}`);
      this.page.currentPage = pageNo;
      const size = this.page.pageSize;
      this.getList(pageNo, size);
    },
    // 编辑模态框
    handleEdit(index, row) {
      this.editDialog.visible = true;
      if (index !== undefined && row !== undefined) {
        this.showPrise = true;
        this.showRentPrise = false;
        const title = `审核`;
        this.editDialog.title = title;
        const data = row;
        this.editDialog.data = data;
      } else {
        this.showRentPrise = true;
        this.showPrise = false;
        this.editDialog.title = "添加";
        this.editDialog.data = {};
      }
    },
    // 修改数据
    handleSubmit() {},
    // 删除
    handleDel() {},
    closeDialog(name) {
      if (name === "editDialog") {
        this[name].submitVisible = false;
        this[name].data = null;
      }
      this[name].visible = false;
    },
    // 图片上传成功
    fileSuccess(res) {
      this.imgUrl = res.url;
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-dialog .el-dialog__title {
  font-size: 12px;
}
/deep/ .el-dialog .el-form-item__label {
  font-size: 12px;
}
.el-date-editor.el-input {
  width: 100%;
}
/deep/ .el-dialog__body {
  // height: 500px;
  overflow: hidden;
  // overflow-y: scroll;
}
.el-select{
  width: 100%;
}
</style>